package com.am.mosl.cityandroid.util;

import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

/**
 * Created by mosl on 14-7-23.
 * 设备帮助类
 */
public class DeviceUtil {

    /*
       获取设备Id
     */
    public static final String getDeviceId(Activity activity){
        TelephonyManager tm = (TelephonyManager)
                activity.getSystemService(activity.TELEPHONY_SERVICE);
        return tm.getDeviceId();

    }
    /*
       dip to px
       px像素
     */
    public static int dip2px(Context context, float dipValue){
           float scale = context.getResources().getDisplayMetrics().density;
           return (int)(dipValue * scale +0.5f);
    }
    /*
      px to dip
      像素 to dip
     */
    public static int px2dip(Context context, float pxValue){
        float scale =  context.getResources().getDisplayMetrics().density;
        return (int)(pxValue / scale +0.5f);
    }

    /*
    获取屏幕宽度 px
     */
    public static int getWindowWidth(Activity activity){
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        return  dm.widthPixels;
    }

    /*
    获取屏幕高度
     */
    public static int getWindowHeight(Activity activity){

        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        return  dm.heightPixels;
    }
}
